package com.guoliang.wechatpushing.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.guoliang.wechatpushing.json.JsonPackageObject;
import com.guoliang.wechatpushing.service.*;
import com.guoliang.wechatpushing.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：Leo
 * @date ：Created in 2022/10/18 14:22
 * @description：对消息所需参数进行添加
 */
@Service
@Slf4j
public class HandlerServiceImpl implements HandlerService {
    @Autowired
    WeatherService weatherService;
    @Autowired
    DateService dateService;
    @Autowired
    AphorismService aphorismService;
    @Autowired
    TranslateService translateService;
    Map<String,Object> resultMap=new HashMap<>();
    @Override
    public Map<String, Object> handlerMessage() {
      //结果map添加data
        String date = DateUtils.getDate();
        JsonPackageObject first = new JsonPackageObject(date, "#FF6600");
        resultMap.put("first",first);
        //添加城市、天气、温度等
        JSONObject weather = weatherService.nowWeather();
        JsonPackageObject city = new JsonPackageObject(weather.getString("city"), "#3366CC");
        resultMap.put("city",city);
        JsonPackageObject wea = new JsonPackageObject(weather.getString("wea"), "#33FFCC");//待更新 不同天气颜色不同
        resultMap.put("weather",wea);
        JsonPackageObject tem_day = new JsonPackageObject(weather.getString("tem_day")+"℃", "#33CCCC");
        resultMap.put("maxTemperature",tem_day);
        JsonPackageObject tem_night = new JsonPackageObject(weather.getString("tem_night")+"℃", "#FF3333");
        resultMap.put("minTemperature",tem_night);
        String wind=weather.getString("win")+" "+weather.getString("win_speed");
        JsonPackageObject win=new JsonPackageObject(wind,"#669999");
        resultMap.put("wind",win);
        JsonPackageObject humidity = new JsonPackageObject(weather.getString("humidity"), "#6699FF");
        resultMap.put("wet",humidity);
        //将接下来三天天气添加
        String[] strings = weatherService.nextWeather();
        JsonPackageObject w1=new JsonPackageObject(strings[0],"#33FFCC");
        resultMap.put("day1_wea",w1);
        JsonPackageObject w2=new JsonPackageObject(strings[1],"#33FFCC");
        resultMap.put("day2_wea",w2);
        JsonPackageObject w3=new JsonPackageObject(strings[2],"#33FFCC");
        resultMap.put("day3_wea",w3);
        //添加各种日期
        try {
            String togetherDays = dateService.togetherDays();
            String girlBirthdays = dateService.girlBirthdays();
            String boyBirthdays = dateService.boyBirthdays();
            JsonPackageObject date1=new JsonPackageObject(togetherDays,"#FF0099");
            JsonPackageObject date2=new JsonPackageObject(girlBirthdays,"#FF9966");
            JsonPackageObject date3=new JsonPackageObject(boyBirthdays,"#FF9966");
            resultMap.put("togetherDate",date1);
            resultMap.put("birthDate1",date2);
            resultMap.put("birthDate2",date3);
            String aphorism = aphorismService.getAphorism();
            JsonPackageObject note_Zh = new JsonPackageObject(aphorism, "#336666");
            resultMap.put("note_Zh",note_Zh);
            String translate = translateService.translate(aphorism);
            log.info(translate);
            JsonPackageObject note_En=new JsonPackageObject(translate,"#336666");
            resultMap.put("note_En",note_En);
        } catch (ParseException | IOException e) {
            e.printStackTrace();
            log.info("日期、名言出现异常");
        }
        return resultMap;
    }
}
